import java.util.ArrayList;


public class DState {

	int id;
	
	ArrayList<DState> next;
	
	static int currentId=0;
	
	boolean mark;
	
	ArrayList<State> nfaTracker;
	
	public DState(){
		this.id=currentId++;
		
		next = new ArrayList<DState>(256);
		while(next.size()<256)next.add(null);
		nfaTracker = new ArrayList<State>();
	}
	
	public DState(ArrayList<State> nfaStates){
		
		this();
		nfaTracker.addAll(nfaStates);
	}
	
	public void addNFAState(State s){
		nfaTracker.add(s);
		
	}
	
	public void addNFAState(ArrayList<State> s){
		nfaTracker.addAll(s);
	}

	public boolean checkEquality(ArrayList<State> s){
		
		if(s.size()!=nfaTracker.size()){
			return false;
		}
		
		for(int i=0; i<s.size(); i++){
			if(!nfaTracker.contains(s.get(i))){
				return false;
			}
		}
		return true;
	}
	
	public void addTransition(int startIndex, int endIndex, DState destination){
		for(int i=startIndex; i<=endIndex; i++){
			next.set(i, destination);
		}
	}
	
	public DState getNext(int index){
		if(index<0||index>255){
			index=0;
		}
		return next.get(index);
	}
	
	public ArrayList<DState> getTransitions() {
		return next;
	}
	
	public void setId(int i){
		id=i;
	}
	
	public ArrayList<String> getTokenNames(){
		ArrayList<String> s = new ArrayList<String>();
		
		for(int i=0; i<nfaTracker.size(); i++){
			if(nfaTracker.get(i).isAccepting()){
				s.add(nfaTracker.get(i).getTokenName());
			}
		}
		return s;
	}
	
	public int getId(){
		return id;
	}
	
	public ArrayList<State> getNFAStates(){
		return nfaTracker;
	}
	
	
	
}
